package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.UserCount;
import com.juyu.miliao.common.dataSource.tool.distributeOperate.DistributeOperate;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserCountDao {
    @Autowired
    private SqlSession sqlSession;


    @Operate("strategy('byUserId', #entity.userId)")
    public int updateUserCount(UserCount entity) {
        return sqlSession.update("updateUserCount", entity);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addPrivateSum(long userId) {
        return sqlSession.update("addPrivateSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int reducePrivateSum(long userId) {
        return sqlSession.update("reducePrivateSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addVisitorSum(long userId) {
        return sqlSession.update("addVisitorSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addFollowSum(long userId) {
        return sqlSession.update("addFollowSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addFansSum(long userId) {
        return sqlSession.update("addFansSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int reduceFollowSum(long userId) {
        return sqlSession.update("reduceFollowSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int reduceFansSum(long userId) {
        return sqlSession.update("reduceFansSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addMGradeSum(long userId, double mGradeSum) {
        Map<String, Object> params = new HashMap<>(4);
        params.put("userId", userId);
        params.put("mGradeSum", mGradeSum);
        return sqlSession.update("addMGradeSum", params);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addVGradeSum(long userId, int vGradeSum) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("vGradeSum", vGradeSum);
        return sqlSession.update("addVGradeSum", params);
    }

    @Operate("strategy('byUserId', #userId)")
    public int reduceMGradeSum(long userId, double mGradeSum) {
        Map<String, Object> params = new HashMap<>(4);
        params.put("userId", userId);
        params.put("mGradeSum", mGradeSum);
        return sqlSession.update("reduceMGradeSum", params);
    }

    @Operate("strategy('byUserId', #userId)")
    public int reduceVGradeSum(long userId, int vGradeSum) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("vGradeSum", vGradeSum);
        return sqlSession.update("reduceVGradeSum", params);
    }

    //归约查询
    @DistributeOperate(ds = "miliao-user")
    public List<UserCount> findUserCountMVGradeSum() {
        return sqlSession.selectList("findUserCountMVGradeSum");
    }

    @Operate("strategy('byUserId', #userId)")
    public UserCount findCallTimeSumUserId(long userId) {
        return sqlSession.selectOne("findCallTimeSumUserId", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addShareSum(long userId) {
        return sqlSession.update("addShareSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public UserCount getShareAndRewardSumById(long userId) {
        return sqlSession.selectOne("getShareAndRewardSumById", userId);
    }

    @Operate("strategy('byUserId', #shareUserId)")
    public int findUserCountByUserId(long shareUserId) {
        return sqlSession.selectOne("findUserCountByUserId", shareUserId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addRewardSum(long userId) {
        return sqlSession.update("addRewardSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addUserCallSuccessSum(long userId) {
        return sqlSession.update("addUserCallSuccessSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addUserCallFailSum(long userId) {
        return sqlSession.update("addUserCallFailSum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addVideoNum(long userId) {
        return sqlSession.update("addVideoNum", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int reduceVideoNum(long userId) {
        return sqlSession.update("reduceVideoNum", userId);
    }
    @Operate("strategy('byUserId', #userId)")
    public UserCount selectUserCountByUserId(long userId) {
        return sqlSession.selectOne("selectUserCountByUserId", userId);
    }
    @Operate("strategy('byUserId', #userId)")
    public int addCallSuccessSumVoice(long userId) {
        return sqlSession.update("addCallSuccessSumVoice", userId);
    }
    @Operate("strategy('byUserId', #userId)")
    public int addCallSuccessSumVedio(long userId) {
        return sqlSession.update("addCallSuccessSumVedio", userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public int addUserEnergySum(long userId, int energy) {
        Map<String, Object> params = new HashMap<>(4);
        params.put("userId", userId);
        params.put("energy", energy);
        return sqlSession.update("addUserEnergySum", params);
    }

    @Operate("strategy('byUserId', #userId)")
    public void updateGiftDiamond(long userId, double diamond) {
        Map<String, Object> params = new HashMap<>(4);
        params.put("userId", userId);
        params.put("diamond", diamond);
        sqlSession.update("updateGiftDiamond", params);
    }

    @Operate("strategy('byUserId', #userId)")
    public void updateVideoDiamond(long userId, double diamond) {
        Map<String, Object> params = new HashMap<>(4);
        params.put("userId", userId);
        params.put("diamond", diamond);
        sqlSession.update("updateVideoDiamond", params);
    }

    @Operate("strategy('byUserId', #userId)")
    public int updateIntegralSum(long userId, int integralValue) {
        Map<String, Object> params = new HashMap<>(4);
        params.put("userId", userId);
        params.put("integralValue", integralValue);
        return sqlSession.update("updateIntegralSum",params);
    }
}
